var DocData = {
    userId: '',
    patientId: '',
    detailURL: '/xrtn-manager/order/gotoOrderDetail',
    goodsList: false,
    serviceList: false,
    payWay: -1,
    payWays: -1,
}

//选择的  订单 tab  全部  已完成  已取消
var orderIndex = null;
//选择的  卡项 tab
var orderKaIndex = 0;

initView();
function initView() {
    var tabIndex = $.session.get("order_tab");
    var paymentmethodstr = $.session.get(tabIndex + "order_paymentmethodstr");
    if (undefined == paymentmethodstr) {
        $('#paymentmethod').val("-1");
    } else {
        $('#paymentmethod').val(paymentmethodstr);
    }
    var order_startDate = $.session.get(tabIndex + "order_startDate");
    var order_endDate = $.session.get(tabIndex + "order_endDate");
    if (undefined == order_startDate || undefined == order_endDate) {
        $('#datetimepicker').val(getNowFormatDate());
        $('#datetimepickerend').val(getNowFormatDate());
    } else {
        $('#datetimepicker').val(order_startDate);
        $('#datetimepickerend').val(order_endDate);
    }
    var userPhone = $.session.get(tabIndex + "order_userPhone");
    if (undefined == userPhone) {
        $('#mobile_and_orderId').val("");
    } else {
        $('#mobile_and_orderId').val(userPhone);
    }
    var tabIndexSelect = $.session.get(tabIndex + "tabIndexSelect");
    if (undefined == tabIndexSelect) {
        orderIndex = null;
        $('#0_select').addClass("active_bgc").siblings().removeClass("active_bgc");
        $('#00_select').addClass("active_bgc").siblings().removeClass("active_bgc");
        $('#000_select').addClass("active_bgc").siblings().removeClass("active_bgc");
    } else {
        if (0 == tabIndexSelect) {
            $('#0_select').addClass("active_bgc").siblings();
            $('#1_select').removeClass("active_bgc");
            $('#2_select').removeClass("active_bgc");
            $('#3_select').removeClass("active_bgc");
            $('#4_select').removeClass("active_bgc");
            $('#5_select').removeClass("active_bgc");

            $('#00_select').addClass("active_bgc").siblings();
            $('#01_select').removeClass("active_bgc");
            $('#02_select').removeClass("active_bgc");
            $('#03_select').removeClass("active_bgc");

            $('#000_select').addClass("active_bgc").siblings();
            $('#001_select').removeClass("active_bgc");
            $('#002_select').removeClass("active_bgc");
        } else if (1 == tabIndexSelect) {
            $('#1_select').addClass("active_bgc").siblings();
            $('#3_select').removeClass("active_bgc");
            $('#2_select').removeClass("active_bgc");
            $('#0_select').removeClass("active_bgc");
            $('#4_select').removeClass("active_bgc");
            $('#5_select').removeClass("active_bgc");

            $('#01_select').addClass("active_bgc").siblings();
            $('#03_select').removeClass("active_bgc");
            $('#02_select').removeClass("active_bgc");
            $('#00_select').removeClass("active_bgc");

            $('#001_select').addClass("active_bgc").siblings();
            $('#002_select').removeClass("active_bgc");
            $('#000_select').removeClass("active_bgc");
        } else if (2 == tabIndexSelect) {
            $('#2_select').addClass("active_bgc").siblings();
            $('#1_select').removeClass("active_bgc");
            $('#3_select').removeClass("active_bgc");
            $('#0_select').removeClass("active_bgc");
            $('#4_select').removeClass("active_bgc");
            $('#5_select').removeClass("active_bgc");

            $('#02_select').addClass("active_bgc").siblings();
            $('#01_select').removeClass("active_bgc");
            $('#03_select').removeClass("active_bgc");
            $('#00_select').removeClass("active_bgc");

            $('#002_select').addClass("active_bgc").siblings();
            $('#001_select').removeClass("active_bgc");
            $('#000_select').removeClass("active_bgc");
        } else if (3 == tabIndexSelect) {
            $('#3_select').addClass("active_bgc").siblings();
            $('#1_select').removeClass("active_bgc");
            $('#2_select').removeClass("active_bgc");
            $('#0_select').removeClass("active_bgc");
            $('#4_select').removeClass("active_bgc");
            $('#5_select').removeClass("active_bgc");

            $('#03_select').addClass("active_bgc").siblings();
            $('#01_select').removeClass("active_bgc");
            $('#02_select').removeClass("active_bgc");
            $('#00_select').removeClass("active_bgc");
        } else if (4 == tabIndexSelect) {
            $('#4_select').addClass("active_bgc").siblings();
            $('#1_select').removeClass("active_bgc");
            $('#2_select').removeClass("active_bgc");
            $('#0_select').removeClass("active_bgc");
            $('#3_select').removeClass("active_bgc");
            $('#5_select').removeClass("active_bgc");

            $('#03_select').addClass("active_bgc").siblings();
            $('#01_select').removeClass("active_bgc");
            $('#02_select').removeClass("active_bgc");
            $('#00_select').removeClass("active_bgc");
        } else if (5 == tabIndexSelect) {
            $('#5_select').addClass("active_bgc").siblings();
            $('#1_select').removeClass("active_bgc");
            $('#2_select').removeClass("active_bgc");
            $('#0_select').removeClass("active_bgc");
            $('#4_select').removeClass("active_bgc");
            $('#3_select').removeClass("active_bgc");

            $('#03_select').addClass("active_bgc").siblings();
            $('#01_select').removeClass("active_bgc");
            $('#02_select').removeClass("active_bgc");
            $('#00_select').removeClass("active_bgc");
        }
        if (tabIndex == 1) {
            if (tabIndexSelect == 0) {
                orderIndex = null;
            } else if (tabIndexSelect == 1) {
                orderIndex = 3;
            } else if (tabIndexSelect == 2) {
                orderIndex = 5; // 待完善
            } else if (tabIndexSelect == 3) {
                orderIndex = 0;
            } else if (tabIndexSelect == 4) {
                orderIndex = 6; // 已失效
            } else if (tabIndexSelect == 5) {
                orderIndex = 4;
            }
        } else if (tabIndex == 3) {
            if (tabIndexSelect == 1) {
                orderIndex = 3;
            } else if (tabIndexSelect == 2) {
                orderIndex = 0;
            } else if (tabIndexSelect == 3) {
                orderIndex = 4;
            } else if (tabIndexSelect == 0) {
                orderIndex = null;
            }
        } else {
            if (tabIndexSelect == 1) {
                orderKaIndex = 1;
            }
            if (tabIndexSelect == 2) {
                orderKaIndex = 2;
            }
            if (tabIndexSelect == 0) {
                orderKaIndex = null;
            }
        }
    }

}

var flag = (baseFn.notNull(baseFn.getQueryString('flag', true)) ? baseFn.getQueryString('flag') : _curflag);

var tabNum = $.session.get("order_tab");
if (undefined == tabNum) {
    $.session.set("order_tab", 1);
    // flag = 1;
    $('.num1').addClass("bespeak_active").siblings();
    $('.num2').removeClass("bespeak_active");
    $('.num3').removeClass("bespeak_active");
    // flag = 1;

    $('#one_ka').removeClass('hidden');
    $('#two_ka').addClass('hidden');
    $('#three_ka').addClass('hidden');
    $('#four_ka').addClass('hidden');
    //权限控制 订单管理-绿色通道
    if (baseFn.getPower(12)) {
        $('.js_power_12').addClass('hidden');
    }

    $('.js_card_wrap').addClass('hidden')
    $('.js_order_wrap').removeClass('hidden')
    $('.js_goods_wrap').addClass('hidden')
    $('.orderlist').show();
    $('.zcwrap_edit').hide();

    $("table[type='innerTable']").remove();
    // search();
} else {
    switch (tabNum) {
        case "1":
            // flag = 1;
            $('.num1').addClass("bespeak_active").siblings();
            $('.num2').removeClass("bespeak_active");
            $('.num3').removeClass("bespeak_active");
            // flag = 1;

            $('#one_ka').removeClass('hidden');
            $('#two_ka').addClass('hidden');
            $('#three_ka').addClass('hidden');
            $('#five_ka').addClass('hidden');
            $('#four_ka').addClass('hidden');
            //权限控制 订单管理-绿色通道
            if (baseFn.getPower(12)) {
                $('.js_power_12').addClass('hidden');
            }

            $('.js_card_wrap').addClass('hidden')
            $('.js_order_wrap').removeClass('hidden')
            $('.js_goods_wrap').addClass('hidden')
            $('.orderlist').show();
            $('.zcwrap_edit').hide();

            $("table[type='innerTable']").remove();
            // search();
            break;
        case "2":
            // flag = 2;
            $('.num2').addClass("bespeak_active").siblings();
            $('.num1').removeClass("bespeak_active");
            $('.num3').removeClass("bespeak_active");
            // flag = 2;

            $('#one_ka').addClass('hidden');
            $('#two_ka').removeClass('hidden');
            $('#three_ka').removeClass('hidden');
            $('#five_ka').removeClass('hidden');
            $('#four_ka').addClass('hidden');
            //权限控制 工作台-快速开卡
            if (baseFn.getPower(4)) {
                $('.js_power_4').addClass('hidden');
            }
            //权限控制 工作台-会员储值
            if (baseFn.getPower(5)) {
                $('.js_power_5').addClass('hidden');
            }

            $('.js_order_wrap').addClass('hidden')
            $('.js_card_wrap').removeClass('hidden')
            $('.js_goods_wrap').addClass('hidden')
            $('.orderlist').show();
            $('.zcwrap_edit').hide();

            $("table[type='innerTable']").remove();
            // search();
            break;
        case "3":
            $('.num3').addClass("bespeak_active").siblings();
            $('.num1').removeClass("bespeak_active");
            $('.num2').removeClass("bespeak_active");
            // flag = 3;

            $('#one_ka').addClass('hidden');
            $('#two_ka').addClass('hidden');
            $('#three_ka').addClass('hidden');
            $('#five_ka').addClass('hidden');
            $('#four_ka').removeClass('hidden');

            $('.js_card_wrap').addClass('hidden')
            $('.js_order_wrap').addClass('hidden')
            $('.js_goods_wrap').removeClass('hidden')

            $('.orderlist').show();
            $('.zcwrap_edit').hide();

            $("table[type='innerTable']").remove();
            // search();
            break;
    }
}

// $('#datetimepicker').val(getNowFormatDate())
// $('#datetimepickerend').val(getNowFormatDate())
var orderlistDT = '', cardlistDT = '', goodslistDT = '';
//  判断选择的是订单 还是 卡项
//权限管理
var _curflag = $($('.Baby_Healthy_home_right_top_list>li:not(".hidden")')[0]).attr('rel');
/*订单列表 */
var orderlistDTdata = {
    limit: 10,
    dayType: 0
}//订单列表data渲染数据
var goodslistDTdata = {
    limit: 10,
    payWay: 6
}//商品列表data渲染数据
function OrderListDTFn(data) {
    var _data = data
    if (orderlistDT == '') {
        for (var i in _data) {
            orderlistDTdata[i] = _data[i]
        }
        orderlistDT = baseFn.rpDataTables('.js_order_list', {
            ajUrl: baseUrl.base + baseUrl.order + 'selectOrderPageList',
            ajDataSrc: "results",
            select: true,
            ajDataSrc: "results.rows",
            ajData: orderlistDTdata,
            service: true,
            sessionPageKey: 'orderOnePage',
            curPage: 1,
            autoWidth: false,
            ajType: 'get',
            // displayLength:1,
            scrollY: windowOffsetData.tableHeight(),
            // scrollY: 500,
            columns: [
                // {"data":null,defaultContent:'',className:'select-checkbox'},
                {
                    data: "orderId",
                    width: '15%',
                    defaultContent: '',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        if (!baseFn.notNull(row.orderNo)) {
                            row.orderNo = '无订单号'
                        }
                        if (baseFn.notNull(row.orderTime)) {
                            row.orderTime = baseFn.timestampToTime(row.orderTime)
                        } else {
                            row.orderTime = '无支付时间'
                        }
                        return '<p>订单号：' + row.orderNo + '</p><p>支付时间：' + row.orderTime + '</p>'

                    }
                },
                {
                    data: "orderPayCost", width: '10%', defaultContent: '无', render: function (data, type, row, meta) {
                    return '￥ ' + data
                }
                },
                {
                    "data": "payWay", width: '10%', defaultContent: '无', render: function (data, type, row, meta) {
                    var _txt = ''
                    if (row.orderState == '已关闭') {
                        data = 9
                        row.payWays = 9
                    } else if (row.orderState == '待支付') {
                        data = 8;
                        row.payWays = 8
                    } else if (row.orderState == '已完成') {
                        if (data == 7 || row.payWays == 7) {
                            row.payWays = 7
                            data = 7
                        }
                    }
                    var _payWayStrArr = ['余额', '支付宝', '微信', '现金', 'Pos机', '丁香云优惠券', '商品订单', '他人代付', '待支付', '已关闭', '无']
                    var _payWayStr = baseFn.notNull2(_payWayStrArr[data], true, '其他'),
                        _payWaysStr = baseFn.notNull2(_payWayStrArr[row.payWays], true, '其他')
                    _txt = _payWayStr + ' + ' + _payWaysStr
                    if (_payWayStr == _payWaysStr && _payWayStr != '其他') {
                        _txt = _payWayStr
                    } else if (data == 6) {
                        _txt = _payWaysStr
                    } else if (_payWayStr == '其他' && _payWaysStr != '其他') {
                        _txt = _payWaysStr
                    } else if (_payWayStr != '其他' && _payWaysStr == '其他') {
                        _txt = _payWayStr
                    }
                    return _txt
                }
                },
                {
                    "data": "userName",
                    width: '10%',
                    defaultContent: '无',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        // return '<p>' + (baseFn.notNull(data)?data:'无') + '</p><p>' + (baseFn.notNull(row.userPhone)?row.userPhone:'无') + '</p>'
                        return '<a href="javascript:void(0)" class="font_blue js_order_btn vipdetail" data-vals="' + row.userId + '">' + (baseFn.notNull(data) ? data : '无') + '</a><p>' + (baseFn.notNull(row.userPhone) ? baseFn.getHidePhoneStr(row.userPhone) : '无') + '</p>'
                    }
                },
                {"data": "subclinicName", width: '10%', defaultContent: '无'},
                {"data": "doctorName", width: '10%', defaultContent: '无'},
                {
                    "data": "orderId",
                    width: '11%',
                    serviceCost: '无',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        var orderStateStr = "";
                        if (row.orderState == "已完成") {
                            if (row.treatmentState == 0) {
                                orderStateStr = "待完善";
                            } else if (row.treatmentState == 2) {
                                orderStateStr = "已失效";
                            } else {
                                orderStateStr = "已完成";
                            }
                        } else {
                            orderStateStr = row.orderState;
                        }
                        var _txt = '<p>' + orderStateStr + '</p>';
                        //权限管理 订单管理 - 13 就诊订单详情
                        if (!baseFn.getPower(13)) {
                            _txt += '<a class="font_blue js_order_btn detail" href="javascript:void(0)" data-vals="' + data + '">查看订单</a>'
                        }
                        if (orderStateStr == "待支付") {
                            _txt = '<p>' + row.orderState + '</p>';
                            //权限管理 订单管理 - 73 就诊订单继续支付
                            if (!baseFn.getPower(73)) {
                                _txt += '<a class="font_blue js_order_btn gos" href="javascript:void(0)" data-vals="' + data + '">继续支付</a>'
                            }
                        } else if (orderStateStr == "待完善") {
                            _txt = '<p>' + orderStateStr + '</p>';
                            //权限管理 订单管理 - 84 完善病历
                            if (!baseFn.getPower(84)) {
                                _txt += '<a class="font_blue js_order_btn complete" href="javascript:void(0)" data-vals="' + data + '">完善病历</a>'
                            }
                        }
                        return _txt;

                    }
                }
            ],
            initComplete: function () {

            },
            drawCallback: function (settings) {
                $('.js_order_btn.vipdetail').off('click').on('click', function () {
                    var _id = $(this).data('vals')
                    baseFn.goPath('gotoVipDetail', {userId: _id})
                })
                $('.js_order_btn.detail').off('click').on('click', function () {
                    var _id = $(this).data('vals')
                    var _tr = $(this).parents('tr')
                    var _data = orderlistDT.row(_tr).data()
                    baseFn.goPath('gotoOrderDetail', {orderId: _id, orderType: 0, treatmentState: _data.treatmentState})

                })
                $('.js_order_btn.gos').off('click').on('click', function () {
                    var _tr = $(this).parents('tr')
                    var _data = orderlistDT.row(_tr).data()
                    //结账
                    baseFn.goPath('gotoFastOrder', {
                        bookingId: _data.bookingId,
                        userId: _data.userId,
                        subclinicId: _data.subclinicId,
                        doctorId: _data.doctorId,
                        patientId: _data.patientId,
                        orderId: _data.orderId
                    })
                })
                $('.js_order_btn.complete').off('click').on('click', function () {
                    var _tr = $(this).parents('tr')
                    var _data = orderlistDT.row(_tr).data()
                    //完善病历
                    baseFn.goPath('gotoFastOrder', {
                        bookingId: _data.bookingId,
                        userId: _data.userId,
                        subclinicId: _data.subclinicId,
                        doctorId: _data.doctorId,
                        patientId: _data.patientId,
                        orderId: _data.orderId,
                        bookingStatus: 4,
                        treatmentState: _data.treatmentState
                    })
                })
            },
            page: function (self, e, sets, json) {
            }
        })

    } else {
        baseFn.objDelElm(orderlistDTdata, 'limit')
        for (var i in _data) {
            orderlistDTdata[i] = _data[i]
        }
        // orderlistDT.settings()[0].ajax.data = _data
        orderlistDT.ajax.reload()
    }
}
function GoodsListDTFn(data) {
    var _data = data
    if (goodslistDT == '') {
        for (var i in _data) {
            goodslistDTdata[i] = _data[i]
        }
        goodslistDT = baseFn.rpDataTables('.js_goods_list', {
            ajUrl: baseUrl.base + baseUrl.order + 'selectOrderPageList',
            ajDataSrc: "results",
            select: true,
            ajDataSrc: "results.rows",
            ajData: goodslistDTdata,
            service: true,
            autoWidth: false,
            sessionPageKey: 'orderTwoPage',
            ajType: 'get',
            // displayLength:1,
            scrollY: windowOffsetData.tableHeight(),
            // scrollY: 500,
            columns: [
                // {"data":null,defaultContent:'',className:'select-checkbox'},
                {
                    data: "orderId",
                    width: '15%',
                    defaultContent: '',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        if (!baseFn.notNull(row.orderNo)) {
                            row.orderNo = '无订单号'
                        }
                        if (baseFn.notNull(row.orderTime)) {
                            row.orderTime = baseFn.timestampToTime(row.orderTime)
                        } else {
                            row.orderTime = '无支付时间'
                        }
                        return '<p>订单号：' + row.orderNo + '</p><p>支付时间：' + row.orderTime + '</p>'

                    }
                },
                {
                    data: "orderPayCost", width: '10%', defaultContent: '无', render: function (data, type, row, meta) {
                    return '￥ ' + data
                }
                },
                {
                    "data": "payWay", width: '10%', defaultContent: '无', render: function (data, type, row, meta) {
                    var _txt = ''
                    if (row.orderState == '已关闭') {
                        data = 9
                        row.payWays = 9
                    } else if (row.orderState == '待支付') {
                        data = 8;
                        row.payWays = 8
                    } else if (row.orderState == '已完成') {
                        if (data == 7 || row.payWays == 7) {
                            row.payWays = 7
                            data = 7
                        }
                    }
                    var _payWayStrArr = ['余额', '支付宝', '微信', '现金', 'Pos机', '丁香云优惠券', '商品订单', '他人代付', '待支付', '已关闭', '无']
                    var _payWayStr = baseFn.notNull2(_payWayStrArr[data], true, '其他'),
                        _payWaysStr = baseFn.notNull2(_payWayStrArr[row.payWays], true, '其他')
                    _txt = _payWayStr + ' + ' + _payWaysStr
                    if (_payWayStr == _payWaysStr && _payWayStr != '其他') {
                        _txt = _payWayStr
                    } else if (data == 6) {
                        _txt = _payWaysStr
                    } else if (_payWayStr == '其他' && _payWaysStr != '其他') {
                        _txt = _payWaysStr
                    } else if (_payWayStr != '其他' && _payWaysStr == '其他') {
                        _txt = _payWayStr
                    }
                    return _txt;
                }
                },
                {
                    "data": "userName",
                    width: '10%',
                    defaultContent: '无',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        // return '<p>' + (baseFn.notNull(data)?data:'无') + '</p><p>' + (baseFn.notNull(row.userPhone)?row.userPhone:'无') + '</p>'
                        return '<a href="javascript:void(0)" class="font_blue js_goods_btn vipdetail" data-vals="' + row.userId + '">' + (baseFn.notNull(data) ? data : '无') + '</a><p>' + (baseFn.notNull(row.userPhone) ? baseFn.getHidePhoneStr(row.userPhone) : '无') + '</p>'
                    }
                },
                {"data": "subclinicName", width: '10%', defaultContent: '无'},
                {"data": "doctorName", width: '10%', defaultContent: '无'},
                {
                    "data": "orderId",
                    width: '11%',
                    serviceCost: '无',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        var _txt = '<p>' + row.orderState + '</p>';
                        //权限管理 订单管理 - 13 就诊订单详情
                        if (!baseFn.getPower(13)) {
                            _txt += '<a class="font_blue js_goods_btn detail" href="javascript:void(0)" data-vals="' + data + '">查看订单</a>'
                        }
                        if (row.orderState == "待支付") {
                            _txt = '<p>' + row.orderState + '</p>';
                            //权限管理 订单管理 - 74 商品订单继续支付
                            if (!baseFn.getPower(74)) {
                                _txt += '<a class="font_blue js_goods_btn gos" href="javascript:void(0)" data-vals="' + data + '">继续支付</a>'
                            }
                        }
                        return _txt;

                    }
                }
            ],
            initComplete: function () {

            },
            page: function (self, e, sets, json) {
            },
            drawCallback: function (settings) {
                $('.js_goods_btn.vipdetail').off('click').on('click', function () {
                    var _id = $(this).data('vals')
                    baseFn.goPath('gotoVipDetail', {userId: _id})
                })
                $('.js_goods_btn.detail').off('click').on('click', function () {
                    var _id = $(this).data('vals')
                    baseFn.goPath('gotoOrderDetail', {orderId: _id, orderType: 0, isGoods: true})
                })
                $('.js_goods_btn.gos').off('click').on('click', function () {
                    var _tr = $(this).parents('tr')
                    var _data = goodslistDT.row(_tr).data()
                    //结账
                    baseFn.goPath('gotoHomeGoods', {orderId: _data.orderId})
                })
            }
        })
    } else {
        baseFn.objDelElm(goodslistDTdata, 'limit')
        for (var i in _data) {
            goodslistDTdata[i] = _data[i]
        }
        // orderlistDT.settings()[0].ajax.data = _data
        goodslistDT.ajax.reload()
    }
}
function CardListDTFn(data) {
    var _data = data
    if (cardlistDT == '') {
        cardlistDT = baseFn.rpDataTables('.js_card_list', {
            ajUrl: baseUrl.base + baseUrl.card + 'selectAccountList',
            ajDataSrc: "results",
            select: true,
            ajData: _data,
            autoWidth: false,
            sessionPageKey: 'orderThreePage',
            ajType: 'get',
            scrollY: windowOffsetData.tableHeight(),
            columns: [
                // {"data":null,defaultContent:'',className:'select-checkbox'},
                {
                    data: "orderId",
                    width: '15%',
                    defaultContent: '',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        if (!baseFn.notNull(row.accountNo)) {
                            row.accountNo = '无订单号'
                        }
                        if (baseFn.notNull(row.orderTime)) {
                            row.orderTime = baseFn.timestampToTime(row.orderTime)
                        } else {
                            row.orderTime = '无支付时间'
                        }
                        return '<p>订单号：' + row.accountNo + '</p><p>支付时间：' + row.orderTime + '</p>'

                    }
                },
                {"data": "cardName", width: '10%', defaultContent: '无'},
                {
                    "data": "accountCost", width: '10%', defaultContent: '无', render: function (data, type, row, meta) {
                    return '￥ ' + data
                }
                },
                {
                    "data": "payWay", width: '10%', defaultContent: '无', render: function (data, type, row, meta) {
                    var _txt = ''
                    if (data == -1) {
                        _txt = '未付款'
                    } else if (data == 0) {
                        _txt = '余额'
                    } else if (data == 1) {
                        _txt = '支付宝'
                    } else if (data == 2) {
                        _txt = '微信'
                    } else if (data == 3) {
                        _txt = '现金'
                    } else if (data == 4) {
                        _txt = 'Pos机'
                    } else if (data == 5) {
                        _txt = '次卡'
                    } else {
                        _txt = '其他支付方式'
                    }
                    return _txt
                }
                },
                {
                    "data": "userName",
                    width: '10%',
                    defaultContent: '无',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        return '<a href="javascript:void(0)" class="font_blue js_card_btn vipdetail" data-vals="' + row.userId + '">' + (baseFn.notNull(data) ? data : '无') + '</a><p>' + (baseFn.notNull(row.userPhone) ? baseFn.getHidePhoneStr(row.userPhone) : '无') + '</p>'
                    }
                },
                {"data": "subclinicName", width: '10%', defaultContent: '无'},
                {"data": "doctorName", width: '10%', defaultContent: '无'},
                {
                    "data": "orderId",
                    width: '11%',
                    serviceCost: '无',
                    className: 'td2p',
                    render: function (data, type, row, meta) {
                        // return '<button class="datatablebtn detail" data-vals="'+data+'">查看订单</button>';
                        var _txt = '<p>已完成</p>';
                        //权限管理 订单管理 - 51卡项订单详情
                        if (!baseFn.getPower(51)) {
                            _txt += '<a class="font_blue js_card_btn detail" href="javascript:void(0)" data-vals="' + data + '">查看订单</a>';
                        }
                        return _txt
                    }
                }
            ],
            initComplete: function () {

            },
            page: function () {
            },
            drawCallback: function (settings) {
                $('.js_card_btn.vipdetail').off('click').on('click', function () {
                    var _id = $(this).data('vals')
                    baseFn.goPath('gotoVipDetail', {userId: _id})
                })
                $('.js_card_btn.detail').off('click').on('click', function () {
                    var _id = $(this).data('vals')
                    baseFn.goPath('gotoOrderDetail', {orderId: _id, orderType: 1})
                })
            }
        })
    } else {
        cardlistDT.settings()[0].ajax.data = _data
        cardlistDT.ajax.reload()
    }
}
/*订单管理初始化 */
if ($('.js_order_manage').length == 1) {
    var tabIndex = $.session.get("order_tab");
    // 默认获取分店列表
    baseFn.rpSelect('#store', {
        url: baseUrl.base + "subclinic/selectSubclinicList",
        idKey: "subclinicId",
        textKey: 'subclinicName',
        calFn: function () {
            //权限管理 45 全部门店
            if (SessionData.powerSub) {
                $("#store").val(SessionData.powerSub).trigger('change');
                // $("#store").val(SessionData.powerSub).trigger('change');
            } else {
                $("#store").val(undefined == $.session.get(tabIndex + "order_storestr") ? -1 : $.session.get(tabIndex + "order_storestr")).trigger('change');
            }
            // search(null)
        },
        selFn: function (e) {
            search(null)
        }
    })
    $('#search').on('click', function () {
        search()
    });

    $("#mobile_and_orderId").keydown(function (event) {
        if (event.keyCode == "13") {
            search()
        }
    });

    //    订单    table切换
    $('.bespeak_change_list_actve').on('click', function () {
        var thisIndex = $(this).index();
        var tabIndex = $.session.get("order_tab");
        $.session.set(tabIndex + "tabIndexSelect", thisIndex);
        if (thisIndex == 0) {
            orderIndex = null;
        } else if (thisIndex == 1) {
            orderIndex = 3;
        } else if (thisIndex == 2) {
            orderIndex = 5; // 待完善
        } else if (thisIndex == 3) {
            orderIndex = 0;
        } else if (thisIndex == 4) {
            orderIndex = 6; // 已失效
        } else if (thisIndex == 5) {
            orderIndex = 4;
        }
        $(this).addClass("active_bgc").siblings().removeClass("active_bgc");
        search();
    });
    //    卡项    table切换
    $('.bespeak_change_list_actve_ka').on('click', function () {
        var thisIndex = $(this).index();
        var tabIndex = $.session.get("order_tab");
        $.session.set(tabIndex + "tabIndexSelect", thisIndex);
        if (thisIndex == 1) {
            orderKaIndex = 1;
        } else if (thisIndex == 2) {
            orderKaIndex = 2;
        } else if (thisIndex == 0) {
            orderKaIndex = null;
        }
        $(this).addClass("active_bgc").siblings().removeClass("active_bgc");
        search();
    });
    //时间筛选
    baseFn.dateTimePickGroup('.selDate', {
        startseled: function () {
            //$('input:radio[name=day]').attr('checked', false)
            search()
        },
        endseled: function () {
            //$('input:radio[name=day]').attr('checked', false)
            search()
        }
    })
    $('input:radio[name=day]').on('click', function () {
        var _val = Number($(this).val())
        $('#datetimepickerend').val(baseFn.goDay(0, 1));
        $('#datetimepicker').val(baseFn.goDay(-_val, 1));
        search()
    })
    $("#one_ka").on('click', function () {
        window.location.href = "";
    });
}
/*订单管理 */
// 设置订单列表请求参数

function search(datas) {
    var tabIndex = $.session.get("order_tab");

    var modileAndOrderId = document.getElementById('mobile_and_orderId');
    var storeselect = document.getElementById('store');
    var datetimepickerInput = document.getElementById('datetimepicker');
    var datetimepickerInputEnd = document.getElementById('datetimepickerend');
    var paymentmethodselect = document.getElementById("paymentmethod");
    var paymentmethodstr = paymentmethodselect.options[paymentmethodselect.options.selectedIndex].value;
    $.session.set(tabIndex + "order_paymentmethodstr", paymentmethodstr);
    if (storeselect.options.selectedIndex == -1) {
        storeselect.options.selectedIndex = 0;
    }
    var storestr = storeselect.options[storeselect.options.selectedIndex].value;
    $.session.set(tabIndex + "order_storestr", storestr);
    var datas = {}
    //时间
    if (datetimepickerInputEnd.value != '' || datetimepickerInput.value != '') {
        if (datetimepickerInputEnd.value != '') {
            datas.endDate = datetimepickerInputEnd.value;
        }
        if (datetimepickerInput.value != '') {
            datas.startDate = datetimepickerInput.value;
        }
    } else {
        datas.dayType = 0
    }

    // 续费过期验证
    // var year = datetimepickerInput.value.substring(0, 4);
    // if (parseInt(year) < 2019) {
    //     datas.startDate = '2019-01-01';
    // }
    // 验证end

    $.session.set(tabIndex + "order_startDate", datas.startDate);
    $.session.set(tabIndex + "order_endDate", datas.endDate);
    //付款方式
    if (paymentmethodstr > -1) {
        datas.payWay = paymentmethodstr;
    }
    //查询
    if (modileAndOrderId.value.length > 0) {
        datas.userPhone = modileAndOrderId.value;

        $.session.set(tabIndex + "order_userPhone", datas.userPhone);
    }
    //门店
    if (storestr > -1) {
        datas.subclinicId = storestr;
    }
    if (SessionData.powerSub) {
        datas.subclinicId = SessionData.powerSub
    }
    if (flag == 1) {
        if (orderIndex != null) {
            datas.orderState = orderIndex;
            if (orderIndex == 0) {
                datas.orderState = 0;
                datas.treatmentState = 1;
            } else if (orderIndex == 5) {
                datas.orderState = 0;
                datas.treatmentState = 0;
            } else if (orderIndex == 6) {
                datas.orderState = 0;
                datas.treatmentState = 2;
            }

            datas.isTreatment = 1;
        }
        OrderListDTFn(datas)
    } else if (flag == 2) {
        datas.cardType = orderKaIndex;
        CardListDTFn(datas)
    } else if (flag == 3) {
        if (orderIndex != null) {
            datas.orderState = orderIndex;
        }
        if (baseFn.notNull(datas.payWay)) {
            datas.payWays = datas.payWay
        }
        datas.payWay = 6
        GoodsListDTFn(datas)
    }
}
;
//tab页 切换
$('.Baby_Healthy_home_right_top_list>li').on('click', function () {
    $.session.set('order_tab', $(this).attr('rel'));
    $(this).addClass('bespeak_active').siblings().removeClass('bespeak_active');
});
if ($('.js_order_manage').length == 1) {
    if (undefined == tabNum) {
        flag = 1;
    } else {
        flag = tabNum;
    }
    $('.num1').on('click', function () {
        $('#paymentmethod').val("-1")
        $('#datetimepicker').val();
        $('#datetimepickerend').val();
        $('#mobile_and_orderId').val("");
        $("#today").removeAttr("checked");
        $("#today_3").removeAttr("checked");
        $("#today_7").removeAttr("checked");
        initView();

        if (flag != 1) {
            orderIndex = null
            flag = 1;
        } else {
            return false
        }
        $('#one_ka').removeClass('hidden');
        $('#two_ka').addClass('hidden');
        $('#three_ka').addClass('hidden');
        $('#four_ka').addClass('hidden');
        //权限控制 订单管理-绿色通道
        if (baseFn.getPower(12)) {
            $('.js_power_12').addClass('hidden');
        }

        $('.js_card_wrap').addClass('hidden')
        $('.js_order_wrap').removeClass('hidden')
        $('.js_goods_wrap').addClass('hidden')
        $('.orderlist').show();
        $('.zcwrap_edit').hide();

        $("table[type='innerTable']").remove();
        var tabIndex = $.session.get("order_tab");
        $("#store").val(undefined == $.session.get(tabIndex + "order_storestr") ? -1 : $.session.get(tabIndex + "order_storestr")).trigger('change');
        // search();
    });
    $('.num2').on('click', function () {
        $('#paymentmethod').val("-1")
        $('#datetimepicker').val();
        $('#datetimepickerend').val();
        $('#mobile_and_orderId').val("");
        $("#today").removeAttr("checked");
        $("#today_3").removeAttr("checked");
        $("#today_7").removeAttr("checked");
        initView();

        if (flag != 2) {
            orderKaIndex = 0
            flag = 2;
        } else {
            return false
        }
        $('#one_ka').addClass('hidden');
        $('#two_ka').removeClass('hidden');
        $('#three_ka').removeClass('hidden');
        $('#four_ka').addClass('hidden');
        //权限控制 工作台-快速开卡
        if (baseFn.getPower(4)) {
            $('.js_power_4').addClass('hidden');
        }
        //权限控制 工作台-会员储值
        if (baseFn.getPower(5)) {
            $('.js_power_5').addClass('hidden');
        }

        $('.js_order_wrap').addClass('hidden')
        $('.js_card_wrap').removeClass('hidden')
        $('.js_goods_wrap').addClass('hidden')
        $('.orderlist').show();
        $('.zcwrap_edit').hide();

        $("table[type='innerTable']").remove();
        var tabIndex = $.session.get("order_tab");
        if (!SessionData.powerSub) {
            $("#store").val(undefined == $.session.get(tabIndex + "order_storestr") ? -1 : $.session.get(tabIndex + "order_storestr")).trigger('change');
        }
        // search();
    });
    $('.num3').on('click', function () {
        $('#paymentmethod').val("-1")
        $('#datetimepicker').val();
        $('#datetimepickerend').val();
        $('#mobile_and_orderId').val("");
        $("#today").removeAttr("checked");
        $("#today_3").removeAttr("checked");
        $("#today_7").removeAttr("checked");
        initView();

        if (flag != 3) {
            orderIndex = null
            flag = 3;
        } else {
            return false
        }
        $('#one_ka').addClass('hidden');
        $('#two_ka').addClass('hidden');
        $('#three_ka').addClass('hidden');
        $('#four_ka').removeClass('hidden');

        $('.js_card_wrap').addClass('hidden')
        $('.js_order_wrap').addClass('hidden')
        $('.js_goods_wrap').removeClass('hidden')

        $('.orderlist').show();
        $('.zcwrap_edit').hide();

        $("table[type='innerTable']").remove();
        var tabIndex = $.session.get("order_tab");
        if (!SessionData.powerSub) {
            $("#store").val(undefined == $.session.get(tabIndex + "order_storestr") ? -1 : $.session.get(tabIndex + "order_storestr")).trigger('change');
        }
        // search();
    });
    if (flag == 1) {
        // search()
    } else {
        // var _flag = flag, flag = 1
        // $('.num' + _flag).trigger('click')
    }
}


//订单详情
function getOrderDetails(data) {
    var _data = data;
    if (_data.orderType == 1) {
        $('.userliblist_btn').text('卡项订单');
        $('.js_orderPatient').addClass('hidden')
        $('.num1').removeClass('bespeak_active')
        $('.num3').removeClass('bespeak_active')
        $('.num2').addClass('bespeak_active')
    }
    if (baseFn.notNull(_data.isGoods)) {
        $('.userliblist_btn').text('商品订单');
        $('.js_orderPatient').addClass('hidden')
        $('.js_orderPatient').addClass('hidden')
        $('.num1').removeClass('bespeak_active')
        $('.num3').addClass('bespeak_active')
    }
    $.ajax({
        url: baseUrl.base + "order/selectOrderInfo",
        type: 'get',
        data: _data,
        success: function (data) {
            if (data.code == "0") {
                var nameLabel = document.getElementById("name_label")
                var headImg = document.getElementById("head_patient")
                var namePatientLabel = document.getElementById("name_patient");
                var levelPatientLabel = document.getElementById("level_patient");
                var phonePatientLabel = document.getElementById("phone_patient");

                var orderId = document.getElementById("order_id");
                var orderStatestr = document.getElementById("order_statestr");
                var orderTime = document.getElementById("order_one_time");
                var orderTimeTwo = document.getElementById("order_two_time");
                var orderPayName = document.getElementById("order_pay_name");
                var doctorName = document.getElementById("doctor_name");
                var oredrPayTime = document.getElementById("order_pay_time");
                var oredrPayFlag = document.getElementById("order_pay_flag");
                var orderShop = document.getElementById("order_shop");

                var userInfo = data.results.userInfo;
                var orderInfo = data.results.orderInfo;
                DocData.patientId = orderInfo.patientId;
                DocData.userId = userInfo.userId;
                var dataMsg = data.results.goodsList;
                var dataServiceListMsg = data.results.serviceList;

                if (data.results.goodsList.length > 0) {
                    DocData.goodsList = true;
                }
                if (data.results.serviceList.length > 0) {
                    DocData.serviceList = true;
                }

                DocData.payWay = orderInfo.payWay;
                DocData.payWays = orderInfo.payWays;

                var _txt = ''
                if (orderInfo.orderState == 4) {
                    orderInfo.payWay = 9
                    orderInfo.payWays = 9
                } else if (orderInfo.orderState == 3) {
                    orderInfo.payWay = 8;
                    orderInfo.payWays = 8
                } else if (orderInfo.orderState == 0) {
                    if (orderInfo.payWay == 7 || orderInfo.payWays == 7) {
                        orderInfo.payWays = 7
                        orderInfo.payWay = 7
                    }
                }
                var _payWayStrArr = ['余额', '支付宝', '微信', '现金', 'Pos机', '丁香云优惠券', '商品订单', '他人代付', '待支付', '已关闭', '无']
                if (_data.orderType == 1) {
                    _payWayStrArr[5] = '次卡'
                }
                var _payWayStr = baseFn.notNull2(_payWayStrArr[orderInfo.payWay], true, '其他'),
                    _payWaysStr = baseFn.notNull2(_payWayStrArr[orderInfo.payWays], true, '其他')
                _txt = _payWayStr + ' + ' + _payWaysStr
                if (_payWayStr == _payWaysStr && _payWayStr != '其他') {
                    _txt = _payWayStr
                } else if (orderInfo.payWay == 6) {
                    _txt = _payWaysStr
                } else if (_payWayStr == '其他' && _payWaysStr != '其他') {
                    _txt = _payWaysStr
                } else if (_payWayStr != '其他' && _payWaysStr == '其他') {
                    _txt = _payWayStr
                }
                var orderStatetxt = "";
                var treatmentState = baseFn.getQueryString("treatmentState");
                if (orderInfo.orderState == 0) {
                    if (treatmentState == 0) {
                        orderStatetxt = '待完善'
                    } else if (treatmentState == 2) {
                        orderStatetxt = '已失效'
                    } else {
                        orderStatetxt = '已完成'
                    }
                } else if (orderInfo.orderState == 1) {
                    orderStatetxt = '未接诊'
                } else if (orderInfo.orderState == 2) {
                    orderStatetxt = '调理中'
                } else if (orderInfo.orderState == 3) {
                    orderStatetxt = '待支付'
                } else if (orderInfo.orderState == 4) {
                    orderStatetxt = '已关闭'
                }
                //1:未接诊;2:调理中;3:待支付;4:已关闭
                namePatientLabel.innerText = baseFn.notNull2(orderInfo.patientName, true, '无');
                levelPatientLabel.innerText = userInfo.userGender;
                phonePatientLabel.innerText = baseFn.getHidePhoneStr(userInfo.userPhone);
                nameLabel.innerText = userInfo.userName;
                headImg.src = baseFn.notNull(userInfo.userImg) ? userInfo.userImg : '../images/default.png'

                orderId.innerText = orderInfo.orderNo;
                orderStatestr.innerText = orderStatetxt;
                orderTime.innerText = baseFn.notNull(orderInfo.orderTime) ? baseFn.timestampToTime(orderInfo.orderTime) : '未记录';
                orderTimeTwo.innerText = baseFn.timestampToTime(orderInfo.createTime);
                orderPayName.innerText = baseFn.notNull(orderInfo.cashierName) ? orderInfo.cashierName : "当前用户";
                doctorName.innerText = baseFn.notNull(orderInfo.doctorName) ? orderInfo.doctorName : "当前用户";
                oredrPayTime.innerText = baseFn.notNull(orderInfo.orderTime) ? baseFn.timestampToTime(orderInfo.orderTime) : '未记录';
                orderShop.innerText = orderInfo.subclinicName;
                oredrPayFlag.innerText = _txt;

                $("table[type='innerTableDetails']").remove();

                var _orderDetailList = $('#order_details_list0')
                if (_data.orderType == 0) {
                    var num = dataMsg.length + 1 + dataServiceListMsg.length;
                    var footView = '<table class="bespeak_change_table table_margin_order" type="innerTableDetails">\
                                    <tbody>\
                                    <tr>\
                                        <td style="width:60%;position: relative;text-align: left;">收款时间：' + (baseFn.notNull(orderInfo.orderTime) ? baseFn.timestampToTime(orderInfo.orderTime) : '未记录') + '&nbsp;&nbsp;&nbsp;订单号：' + orderInfo.orderNo + '  </td>\
                                        <td style="width:40%;text-align: right;padding-right:1rem;line-height:2">\
                                            <div class="row" style="margin-top:1rem;">\
                                                <div class="col-sm-3">应收总金额</div>\
                                                <div class="col-sm-9 font_right">¥ ' + orderInfo.orderTotalCost + '</div>\
                                            </div>'

                    if (baseFn.notNull(data.results.cardList) && data.results.cardList.length != 0) {
                        var _cardList = data.results.cardList
                        footView += '<div class="row">\
                                                                <div class="col-sm-3">计次卡消费</div>\
                                                                <div class="col-sm-9 font_right row nopd">'
                        for (var j = 0; j < _cardList.length; j++) {
                            footView += '<div class="col-sm-10">' + _cardList[j].cardName + '</div>\
                                                    <div class="col-sm-2 font_right nopd" style="">-1</div>'
                        }
                        footView += '</div></div>'
                    }
                    if (baseFn.notNull(data.results.cardInfo) && baseFn.notNull(data.results.cardInfo.cardName)) {
                        footView += '<div class="row">\
                                                                <div class="col-sm-3">优惠券</div>\
                                                                <div class="col-sm-9 font_right">' + data.results.cardInfo.cardName + '</div>\
                                                            </div>'
                    }
                    footView += '<div class="row">\
                                                <div class="col-sm-3">优惠合计</div>\
                                                <div class="col-sm-9 font_right">- ¥ ' + ((orderInfo.orderTotalCost - orderInfo.orderPayCost) >= 0 ? (orderInfo.orderTotalCost - orderInfo.orderPayCost) : 0) + '</div>\
                                            </div>\
                                            <div class="row" style="margin-bottom:1rem;">\
                                                <div class="col-sm-3">实收金额</div>\
                                                <div class="col-sm-9 font_right">¥ ' + orderInfo.orderPayCost + '</div>\
                                            </div>\
                                        </td>\
                                    </tr>\
                                    </tbody>\
                                    </table>';
                    _orderDetailList.after(footView);
                    for (var i = 0; i < dataMsg.length; i++) {
                        var boxHtml = '<table class="bespeak_change_table table_margin_order" type="innerTableDetails" id="bodyid">\
                                <tbody>\
                                <tr>\
                                <td style="width:20%;position: relative;text-align: left;">\
                                    <span style="text-align: center;position: absolute;top: 0.1rem">' + dataMsg[i].goodsName + '</span>\
                                </div>\
                                </td>\
                                <td style="width:16%;position: relative;text-align: left;">￥' + dataMsg[i].goodsSumCost + '</td>\
                                <td style="width:16%;position: relative;text-align: left;">' + (baseFn.notNull(orderInfo.doctorName) ? orderInfo.doctorName : '未知') + '</td>\
                                <td style="width:16%;position: relative;text-align: right;padding-right:1rem">' + (baseFn.notNull(orderInfo.cashierName) ? orderInfo.cashierName : '未知') + '</td>\
                                </tr>\
                                </tbody>\
                            </table>';
                        _orderDetailList.after(boxHtml);
                    }
                    for (var i = 0; i < dataServiceListMsg.length; i++) {
                        var boxHtml = '<table class="bespeak_change_table table_margin_order" type="innerTableDetails" id="bodyid">\
                                <tbody>\
                                <tr>\
                                <td style="width:20%;position: relative;text-align: left;">\
                                    <span style="text-align: center;position: absolute;top: 0.1rem">' + dataServiceListMsg[i].serviceName + '</span>\
                                </div>\
                                </td>\
                                <td style="width:16%;position: relative;text-align: left;">￥' + dataServiceListMsg[i].serviceCost + '</td>\
                                <td style="width:16%;position: relative;text-align: left;">' + (baseFn.notNull(orderInfo.doctorName) ? orderInfo.doctorName : '未知') + '</td>\
                                <td style="width:16%;position: relative;text-align: right;padding-right:1rem">' + (baseFn.notNull(orderInfo.cashierName) ? orderInfo.cashierName : '未知') + '</td>\
                                </tr>\
                                </tbody>\
                            </table>';
                        _orderDetailList.after(boxHtml);
                    }
                } else if (_data.orderType == 1) {
                    _orderDetailList = $('#order_details_list1')
                    $('#order_details_list0').addClass('hidden')
                    _orderDetailList.removeClass('hidden');
                    var footView = '<table class="bespeak_change_table table_margin_order" type="innerTableDetails">\
                                <tbody>\
                                <tr>\
                                    <td style="width:68%;position: relative;text-align: left;">收款时间：' + (baseFn.notNull(orderInfo.orderTime) ? baseFn.timestampToTime(orderInfo.orderTime) : '未记录') + '&nbsp;&nbsp;&nbsp;订单号：' + orderInfo.orderNo + '  </td>\
                                    <td style="width:16%;"></td>\
                                    <td style="width:16%;text-align:right;padding-right:1rem">\
                                        <p style="line-height: 2rem;text-align: right;padding-top: 1rem;">应收总金额：¥ ' + orderInfo.accountCost + '</p>\
                                        <p style="line-height: 2rem;text-align: right;">实收金额：¥ ' + orderInfo.accountCost + '</p>\
                                    </td>\
                                </tr>\
                                </tbody>\
                            </table>';
                    _orderDetailList.after(footView);
                    for (var i = 0; i < dataServiceListMsg.length; i++) {
                        var boxHtml = '<table class="bespeak_change_table table_margin_order" type="innerTableDetails" id="bodyid">\
                            <tbody>\
                            <tr>\
                            <td style="width:20%;position: relative;text-align: left;">\
                                <span style="text-align: center;position: absolute;top: 0.1rem">' + dataServiceListMsg[i].serviceName + '</span>\
                            </div>\
                            </td>\
                            <td style="width:16%;position: relative;text-align: left;">￥' + dataServiceListMsg[i].serviceCost + '</td>\
                            <td style="width:16%;position: relative;text-align: right;padding-right:1rem">' + (baseFn.notNull(orderInfo.cashierName) ? orderInfo.cashierName : '未知') + '</td>\
                            </tr>\
                            </tbody>\
                        </table>';
                        _orderDetailList.after(boxHtml);
                    }
                }
                if (baseFn.getPower(90)) {
                    triggerModifyDoctor(orderInfo);
                }

            }
        }
    });
}
$('#find_details').on('click', function () {
    window.location.href = baseUrl.base + "patient/gotoPatientInfo?patientId=" + DocData.patientId + "&userId=" + DocData.userId;
});
//订单详情
if (baseFn.getQueryString('orderId') != null) {
    getOrderDetails({
        orderId: baseFn.getQueryString('orderId'),
        orderType: baseFn.getQueryString('orderType'),
        isGoods: baseFn.getQueryString('isGoods', true)
    })
}
window.onresize = function () {
    windowOffsetData.refresh();
    $(orderlistDT.table().body()).parents('.dataTables_scrollBody').css('max-height', windowOffsetData.tableHeight());
    orderlistDT.draw(false);
    if (baseFn.notNull(goodslistDT)) {
        $(goodslistDT.table().body()).parents('.dataTables_scrollBody').css('max-height', windowOffsetData.tableHeight());
        goodslistDT.draw(false);
    }
    if (baseFn.notNull(cardlistDT)) {
        $(cardlistDT.table().body()).parents('.dataTables_scrollBody').css('max-height', windowOffsetData.tableHeight());
        cardlistDT.draw(false);
    }


}

//门店下拉列表
function triggerModifyDoctor(orderInfo) {
    var orderSubclinicId = orderInfo.subclinicId;
    var orderDoctorId = orderInfo.doctorId;
    baseFn.rpSelect('.js_subclinicId', {
        url: baseUrl.base + "subclinic/selectSubclinicList",
        idKey: "subclinicId",
        textKey: 'subclinicName',
        calFn: function () {
            if (SessionData.powerSub) {
                //权限管理 45 门店是否是全部
                $('select.js_subclinicId').val(SessionData.powerSub).trigger('change');
                selectDoctor({subclinicId: orderSubclinicId, orderDoctorId: orderDoctorId})
            } else if (baseFn.notNull(orderSubclinicId)) {
                $('select.js_subclinicId').val(orderInfo.subclinicId).trigger('change');
                selectDoctor({subclinicId: orderInfo.subclinicId, orderDoctorId: orderDoctorId})
            }
        },
        selFn: function (e) {
            selectDoctor()
        }
    })
}

//选择推拿师
function selectDoctor(data) {
    if (!data) {
        data = {subclinicId: $('.js_subclinicId').val()};
    }
    baseFn.$get({
        url: baseUrl.booking + "selectFreeDoctor",
        data: data,
        canNull: true,
        calFn: function (res) {
            if (baseFn.notNull(res) && res.length != 0) {
                $('.js_doctorId').html('')
                var hasOrderDoctor = false;
                for (var x = 0; x < res.length; x++) {
                    $('.js_doctorId').append("<option value='" + res[x].userId + "'>" + res[x].userName + "</option>");
                    if (res[x].userId == data.orderDoctorId) {
                        hasOrderDoctor = true;
                    }
                }
                if (hasOrderDoctor) {
                    $('.js_doctorId').val(data.orderDoctorId);
                }
            } else {
                $('.js_doctorId').html('')
                baseFn.infoDialog('该门店当前时间段暂无推拿师可以预约', function () {
                }, 1000)
            }
        }
    })
}

$(".js_order_doctoredit").on('click', function () {
    baseFn.dialog({
        title: '修改推拿师',
        width: '25em',
        height: '20vh',
        content: $(".modify_order_doctor"),
        ok: function () {
            var doctorId = $('.js_doctorId').val();
            var doctorSubId = $('.js_subclinicId').val();
            if (!doctorId) {
                baseFn.dialog({
                    title: '提示',
                    content: '请选择要修改的推拿师'
                })
                return;
            }
            baseFn.dialog({
                title: '确定修改该订单的推拿师？',
                content: '修改后，该订单的提成将转移给新的推拿师。',
                ok: function () {
                    var orderType = baseFn.getQueryString('orderType');
                    if (orderType == 0) {
                        baseFn.$post({
                            url: baseUrl.order + 'updateOrderDoctor',
                            data: {orderId: baseFn.getQueryString('orderId'), doctorId: doctorId, doctorSubId: doctorSubId},
                            canNull: true,
                            calFn: function (res) {
                                if (res == 1) {
                                    baseFn.infoDialog('修改成功', function () {
                                        window.location.reload();
                                    })
                                }
                            }
                        })
                    } else if (orderType == 1) {
                        baseFn.$post({
                            url: baseUrl.order + 'updateAccountUserInfoDoctor',
                            data: {orderId: baseFn.getQueryString('orderId'), doctorId: doctorId, doctorSubId: doctorSubId},
                            canNull: true,
                            calFn: function (res) {
                                if (res == 1) {
                                    baseFn.infoDialog('修改成功', function () {
                                        window.location.reload();
                                    })
                                }
                            }
                        })
                    }
                },
                cancel: function () {
                }
            })
        }
    })
});


$(".js_order_pay_flag").on('click', function () {
    $('.service_jyf').each(function () {
        var dom = $($(this).children("div").get(0));
        dom.removeClass('active');
        var num = dom.attr('rel');
        if (num == DocData.payWay) {
            dom.addClass('active');
        }
    })
    $('.service_jyf_two').each(function () {
        var dom = $($(this).children("div").get(0));
        dom.removeClass('active');
        var num = dom.attr('rel');
        if (num == DocData.payWays) {
            dom.addClass('active');
        }
    })
    if (DocData.goodsList) {
        $('.js_paywrap_goods').show();
    } else {
        $('.js_paywrap_goods').hide();
    }
    if (DocData.serviceList) {
        $('.js_paywrap_service').show();
    } else {
        $('.js_paywrap_service').hide();
    }
    baseFn.dialog({
        width: '40em',
        height: '50vh',
        title: '收银台',
        content: $(".modify_order_pay_flag"),
        ok: function () {
            baseFn.dialog({
                title: '确定修改该订单支付方式？',
                content: '确定修改该订单支付方式',
                ok: function () {
                    var orderType = baseFn.getQueryString('orderType');
                    if (orderType == 0) {
                        baseFn.$post({
                            url: baseUrl.order + 'updateOrderInfoByPayFlag',
                            data: {
                                orderId: baseFn.getQueryString('orderId'),
                                payWay: DocData.payWay,
                                payWays: DocData.payWays
                            },
                            canNull: true,
                            calFn: function (res) {
                                if (res == 1) {
                                    window.location.reload();
                                }
                            }
                        });
                    } else if (orderType == 1) {
                        baseFn.$post({
                            url: baseUrl.order + 'updateAccountUserInfoByPayFlag',
                            data: {
                                orderId: baseFn.getQueryString('orderId'),
                                payWay: DocData.payWay
                            },
                            canNull: true,
                            calFn: function (res) {
                                if (res == 1) {
                                    window.location.reload();
                                }
                            }
                        });
                    } else {

                    }

                },
                cancel: function () {

                }
            })
        }
    })
});

$('.payelm').on('click', function () {
    var _parent = $(this).parents('.zccardelm')
    _parent.find('.payelm').removeClass('active')
    $(this).addClass('active')
    if (_parent.attr('rel') == 1) {
        DocData.payWay = $(this).attr('rel')//服务支付方式
    } else {
        DocData.payWays = $(this).attr('rel')//商品支付方式
    }
})


